﻿<%@ Application Language="C#" %>

<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Application["NumOnline"] = 0;
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        Application["NumOnline"] = 0;
    }

    //void Application_Error(object sender, EventArgs e)
    //{
    //    // Code that runs when an unhandled error occurs

    //    // Get the exception object.
    //    Exception exc = Server.GetLastError();
        
    //    HttpContext con = HttpContext.Current;
    //    if(con.Request.Url.ToString().EndsWith(".png"))
    //        return;

    //    // Handle HTTP errors
    //    if (exc.GetType() == typeof(HttpException))
    //    {
    //        // The Complete Error Handling Example generates
    //        // some errors using URLs with "NoCatch" in them;
    //        // ignore these here to simulate what would happen
    //        // if a global.asax handler were not implemented.
    //        if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
    //            return;

    //        //Redirect HTTP errors to HttpError page
    //        //Server.Transfer("HttpErrorPage.aspx");
    //    }

    //    // For other kinds of errors give the user some information
    //    // but stay on the default page
    //    Response.Write("<h2>Global Page Error</h2>\n");
    //    Response.Write(
    //        "<p>" + exc.InnerException + "</p>\n");
    //    Response.Write("Return to the <a href='/Default.aspx'>" +
    //        "Default Page</a>\n");

    //    // Log the exception and notify system operators
    //    ExceptionUtility.LogException(exc, "DefaultPage");
    //    ExceptionUtility.NotifySystemOps(exc);

    //    // Clear the error from the server
    //    Server.ClearError();
    //}

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        Application.Lock();
        int i = (int)Application["NumOnline"]; i++;
        Application["NumOnline"] = i;

        Application.UnLock();
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application.Lock();
        int i = (int)Application["NumOnline"]; i--;
        Application["NumOnline"] = i;
        Application.UnLock();
    }
       
</script>

